/**
 * @file
 * @auth jinguangguo
 * @date 2017/01/19
 */

import filter from '../../../grsc-base/util/filter';
import mathtool from '../../../grsc-base/util/mathtool';

export default {
    /**
     * 获取最大可买数量
     * @param total
     * @param price
     * @param divisor
     */
    getMaxCoin(total, price, divisor,assetCode) {
        let presicion = 4;
        if(assetCode&&assetCode==='BTC'){
            presicion = 8;
        }else if(assetCode&&assetCode==='SMCF1'){
            presicion = 0;
        }
        return filter.floorFix(mathtool.division(mathtool.division(total, price), divisor),presicion);
    },

    /**
     * 支付密码错误处理
     * @param rep
     * @param rules
     */
    doPayPassError(rep, rules) {

        if (rep.code === window.CODE.PAY_PWD && rep.data && rep.data.num) {
            let num = rep.data.num;
            if (3 - num > 0) {
                rules.paypwd.$setError('Incorrect asset password. ' + (3-num) + ' chances left');
            } else {
                rules.paypwd.$setError(window.CODE.PAY_PWD_LOCK.EN);
            }
        } else if (rep.code === window.CODE.PAY_PWD_LOCK.CODE) {
            rules.paypwd.$setError(window.CODE.PAY_PWD_LOCK.EN);
        } else {
            window.error(rep.msg);
        }

    }
}